package com.java.multipledatasource.thread;

/**
 * @author hu
 * @version 1.0
 * @date 2021/1/16 0016 上午 8:52
 * @description
 */
public class VolatileTest {

   volatile   boolean flag = true;
    void m() {
        while (flag) {

        }
        System.out.println("end");
    }

    public static void main(String[] args) {
        VolatileTest volatileTest = new VolatileTest();
        new Thread(volatileTest::m, "t1").start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        volatileTest.flag = false;
        System.out.println("hello");
    }
}
